package com.tc.serial;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import com.tc.gateway.tunnel.TunnelManager;

import android.serialport.SerialPort;


public class SerialFactory {

	static void create(){
		
	}
	public static SerialStream getStream() throws SecurityException, IOException {
		if(WorkingConfig.simulator)
			return new DummyStream();
		else{

			if(WorkingConfig.mainController) {
				SerialPort sp = new SerialPort(new File("/dev/s3c2410_serial3"), 38400);

				return  new SerialStream() {
					@Override
					public InputStream getInputStream() {
						return sp.getInputStream();
					}

					@Override
					public OutputStream getOutputStream() {
						return sp.getOutputStream();
					}

					@Override
					public void ClosePort() {
						sp.close();

					}
				};
			}
				else{
//				if(WorkingConfig.getInstance().getServerIp() != null)
					return TunnelManager.getClient(WorkingConfig.getInstance().getServerIp(),WorkingConfig.getInstance().getPort());
			}
		}
//		return null;
				

	}

}
